﻿using Peter.Common;

namespace Peter.Sdw.Data
{
   /// <summary>
   /// Data object for a style.
   /// </summary>
   public class Style : ViewModelBase
   {
      private string m_End;
      private string m_Start;
      private int m_EndIndex;
      private int m_StartIndex;
      private bool m_SpansMultiple;
      private string m_DisplayText;

      /// <summary>
      /// Gets or Sets the id.
      /// </summary>
      public int Id { get; set; }

      /// <summary>
      /// Gets or Sets the starting index of the style.
      /// </summary>
      public int StartIndex
      {
         get { return this.m_StartIndex; }
         set
         {
            this.m_StartIndex = value;
            this.RaisePropertyChanged ("StartIndex");
            this.UpdateDisplayText ();
         }
      }

      /// <summary>
      /// Gets or Sets the ending index of the style.
      /// </summary>
      public int EndIndex
      {
         get { return this.m_EndIndex; }
         set
         {
            this.m_EndIndex = value;
            this.RaisePropertyChanged ("EndIndex");
            this.UpdateDisplayText ();
         }
      }

      /// <summary>
      /// Gets or Sets if this style spans multiple items (entries/passages).
      /// </summary>
      public bool SpansMultiple
      {
         get { return this.m_SpansMultiple; }
         set
         {
            this.m_SpansMultiple = value;
            this.RaisePropertyChanged ("SpansMultiple");
         }
      }

      /// <summary>
      /// Gets or Sets the start of the style.
      /// </summary>
      public string Start
      {
         get { return this.m_Start; }
         set
         {
            this.m_Start = value;
            this.RaisePropertyChanged ("Start");
            this.UpdateDisplayText ();
         }
      }

      /// <summary>
      /// Gets or Sets the end of the style.
      /// </summary>
      public string End
      {
         get { return this.m_End; }
         set
         {
            this.m_End = value;
            this.RaisePropertyChanged ("End");
            this.UpdateDisplayText ();
         }
      }

      /// <summary>
      /// Gets or Sets how to display this style.
      /// </summary>
      public string DisplayText
      {
         get { return this.m_DisplayText; }
         set
         {
            this.m_DisplayText = value;
            this.RaisePropertyChanged ("DisplayText");
         }
      }

      /// <summary>
      /// Updates the display text.
      /// </summary>
      private void UpdateDisplayText ()
      {
         this.DisplayText = string.Format ("[{0} - {1}] {2} | {3}", this.StartIndex, this.EndIndex, this.Start, this.End);
      }
   }
}
